(function(){
    angular.module('app').controller("agBaseInfoCtrl",function($scope,proxy,$stateParams){
        var id = $stateParams.id;
        console.log(PERMISSION);
        $scope.obj={
            id:id,
            pwd:{},
            'permission':PERMISSION
        }
        $scope.flagObj={}
        $scope.isEditInfo = false;
        $scope.isEditPwd = false;
        proxy.proxy({
            url: STATIC_URL.domian+'/dsp/advertiser',
            data:{id:id},
            success: function(res){
                $scope.obj.info = res.data;
            }
        });
        $scope.confirm = function(){
            if( $scope.obj.pwd.newPasswd !=$scope.obj.pwd.confirmPasswwd){
                layer.msg('新密码两次不一致,请重新输入');
            }else{
                proxy.proxy({
                    url: STATIC_URL.domian+'/dsp/reset/passwd',
                    data:{
                        "oldPasswd":$scope.obj.pwd.oldPasswd,
                        "newPasswd":$scope.obj.pwd.newPasswd
                    },
                    success: function(res){
                        $scope.flagObj.isEditPwd = false;
                        layer.msg('修改成功');
                    }
                })
            }
        };
        //基本信息修改
        $scope.change = function(){
            $scope.flagObj.isEditInfo = ! $scope.flagObj.isEditInfo;
        }
        $scope.modify = function(){
            var x,info = $scope.obj.info;
            for( x in info){
                if(info[x]==''){
                    delete info[x];
                }
            }
            proxy.proxy({
                url: STATIC_URL.domian+'/dsp/advertiser/modify',
                data:{data:info},
                success: function(){
                    $scope.flagObj.isEditInfo = false;
                    layer.msg('修改成功');

                }
            });
        }
    })
})();